package com.example.demo.service.impl;


import java.util.List;

import com.example.demo.dao.RoleDao;
import com.example.demo.entity.Role;
import com.example.demo.entity.RoleAndPermission;
import com.example.demo.mapper.RoleMapper;
import com.example.demo.service.RoleService;
import com.example.demo.util.KeyUtil;

/**
 * 
 * @author Henry.Y
 * @date 2019-05-24
 */
public class RoleServiceImpl implements RoleService {
	
	RoleMapper roleDao= new RoleDao();

	public Role createRole(Role role){
		role.setRoleId(KeyUtil.getRandomID());
		String sqlId="com.example.demo.mapper.RoleMapper.insertRole";
		roleDao.createRole(sqlId,role);
		return role;
	}
	
	public int deleteRole(String id){
		String sqlId= "com.example.demo.mapper.RoleMapper.deleteRole";
		return roleDao.deleteRole(sqlId, id);
	}
	
	public int correlatePermission(List<RoleAndPermission> roleAndPermissionList){
		String sqlId="com.example.demo.mapper.RoleAndPermissionMapper.insertRoleAndPermissionByList";
		return roleDao.correlatePermission(sqlId,roleAndPermissionList);
	}
	
	public int uncorrelatePermission(RoleAndPermission roleAndPermission){
		String sqlId= "com.example.demo.mapper.RoleAndPermissionMapper.deleteRoleAndPermission";
		return roleDao.uncorrelatePermission(sqlId, roleAndPermission);
	}
	
	public int deleteRoleTable(){
		String sqlId= "com.example.demo.mapper.RoleMapper.deleteRoleTable";
		return roleDao.deleteRoleTable(sqlId);
	}
}
